package cn.tedu.boot052.controller;


import cn.tedu.boot052.entity.User;
import cn.tedu.boot052.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserMapper mapper;

    @RequestMapping("/reg")
    public int reg(@RequestBody User user){

        System.out.println(user);
        User u = mapper.selectOne(user.getUsername());
        if (u==null){
            mapper.insert(user);
            return 1;

        }
        return 2;
    }

    @RequestMapping("/login")
    public int login(@RequestBody User user){
        System.out.println(user);
        User u = mapper.selectOne(user.getUsername());
        if (u!=null){
            if (u.getPassword().equals(user.getPassword())){
                return 1;
            }
            return 2;
        }return 3;
    }
}
